<%@ page contentType="text/html;charset=UTF-8" %>

<h1 class="cabelistlateral">Pagamento</h1>
<g:hasErrors bean="${tcePagamentoInstance}">
    <div class="errors">
        <g:renderErrors bean="${tcePagamentoInstance}" as="list" />
    </div>
</g:hasErrors>
<%
def controlador = params.controlador;
def acao        = params.acao;
if(tcePagamentoInstance?.id){
    %>
    <form method="post" action="${createLink(controller:'tcePagamento', action:'update', id:tcePagamentoInstance?.id)}">
    <%
}else{
    %>
    <form method="post" action="${createLink(controller:'tcePagamento', action:'save')}">
    <%
}
%>
    <input type="hidden" name="tce.id" value="${tceInstance.id}"/>
    <input type="hidden" name="controlador" value="${controlador}"/>
    <input type="hidden" name="acao" value="${acao}"/>
    <div class="dialog">
        <table>
            <tbody>
                <tr class="prop cadastrolateral">
                    <td valign="top" class="name" class="value ${hasErrors(bean: tcePagamentoInstance, field: 'dtPagamento', 'errors')}">
                        <label for="dtPagamento"><g:message code="tcePagamento.dtPagamento.label" default="Dt Pagamento" /></label>
                        <br/>
                        <g:datePicker name="dtPagamento" precision="day" value="${tcePagamentoInstance?.dtPagamento}"  />
                    </td>
                    <td valign="top" class="name" class="value ${hasErrors(bean: tcePagamentoInstance, field: 'valor', 'errors')}">
                        <label for="valor"><g:message code="tcePagamento.valor.label" default="Valor" /></label>
                        <br/>
                        <g:textField name="valor" value="${fieldValue(bean: tcePagamentoInstance, field: 'valor')}" />
                    </td>
                </tr>

                <tr class="prop cadastrolateral">
                  <td colspan="2">
                    <table border="0" cellpadding="0" cellspacing="0">
                      <tr>
                          <td valign="top" colspan="2" class="name" class="value ${hasErrors(bean: tcePagamentoInstance, field: 'formaPagamento', 'errors')}">
                             <label for="formaPagamento"><g:message code="tcePagamento.formaPagamento.label" default="Forma Pagamento" /></label>
                             <br/>
                             <select name="formaPagamento.id" class="camposelect">
                                  <option value="">Selecione</option>
                                  <%
                                  for (int i=0; i<formaPagamentoInstance.size(); i++){
                                      %>
                                      <option value="${formaPagamentoInstance?.id[i]}" <%if(formaPagamentoInstance?.id[i]==tcePagamentoInstance?.id){%>selected<%}%>>${formaPagamentoInstance?.descricao[i]}</option>
                                      <%
                                  }
                                  %>
                             </select>
                          </td>
                          <td class="btsalvarlateral">
                              <g:submitButton name="create" class="save" value="SALVAR" />
                          </td>
                      </tr>
                    </table>
                  </td>
                </tr>
            </tbody>
        </table>
    </div>
</form>
<%
if(tcePagamentoInstanceList){
    %>
    <div class="list">
        <table>
            <thead>
                <tr>
                    <g:sortableColumn property="dtPagamento" title="${message(code: 'tcePagamento.dtPagamento.label', default: 'Data Pagamento')}" />
                    <g:sortableColumn property="valor" title="${message(code: 'tcePagamento.valor.label', default: 'Valor')}" />
                    <th><g:message code="tcePagamento.formaPagamento.label" default="Forma" /></th>
                </tr>
            </thead>
            <tbody>
            <g:each in="${tcePagamentoInstanceList}" status="i" var="tcePagamentoInstance">
                <tr class="${(i % 2) == 0 ? 'odd' : 'even'}">
                    <td><g:formatDate date="${tcePagamentoInstance.dtPagamento}" format="dd-MM-yyyy"/></td>
                    <td>${fieldValue(bean: tcePagamentoInstance, field: "valor")}</td>
                    <td>${tcePagamentoInstance?.formaPagamento?.descricao}</td>
                </tr>
            </g:each>
            </tbody>
        </table>
    </div>
    <div class="paginateButtons">
        <g:paginate total="${tcePagamentoInstanceTotal}" />
    </div>
    <%
}else{
    %>
    <div class="list">Nenhuma pagamento encontrado.</div>
    <%
}
%>
